﻿using System;
using System.Collections.Generic;
//using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Hong.Pan.UI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        //public static IConfiguration Config { get; private set; }

        public ServiceProvider ServiceProvider { get; private set; }

        public App()
        {
            //Config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            HostApplicationBuilder builder = Host.CreateApplicationBuilder();
            builder.Services.AddSingleton<IPan, Baidu>();
            builder.Services.AddSingleton<Baidu>();
            ServiceProvider = builder.Services.BuildServiceProvider();
        }

        void App_StartUp(object sender, StartupEventArgs e) {
            Console.WriteLine("app_start");
            //Baidu.Config.client_id = ConfigurationManager.AppSettings["baidu_client_id"];
            IPan pan = ServiceProvider.GetService<Baidu>();

            //Baidu.Config.client_id = Config["baidu_client_id"];
            //Baidu.Login blogin = new Baidu.Login();
            //if (blogin.checkLogin())
            if (pan.IsLogin())
            {
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
            }
            else 
            {
                //Login login = new Login();
                //login.Show();
                LoginBaidu login = new ();
                login.Show();
            }
        }

    }
}
